
//music
export function playSound(path,loop=false) {
		const innerAudioContext = uni.createInnerAudioContext()
		innerAudioContext.autoplay = false  // 是否自动开始播放，默认为 false
		innerAudioContext.loop = loop  // 是否循环播放，默认为 false
		uni.setInnerAudioOption({ // ios在静音状态下能够正常播放音效
		  obeyMuteSwitch: false,   // 是否遵循系统静音开关，默认为 true。当此参数为 false 时，即使用户打开了静音开关，也能继续发出声音。
		  success: function (e) {
		  },
		  fail: function (e) {
		  }
		})
		innerAudioContext.src=path
		innerAudioContext.play()
	
}; 


export function getImageHeight(bili,containHeight,image,width) {
	
	var imgheight = image.height/image.width*width*bili
	//如果图片大于90%就全屏覆盖
	if((imgheight/containHeight)>0.9){
		return containHeight
	}else{
		return imgheight
	}
	
	return today
};

 export function getDateDiff(diffValue) {
    var minute = 60;
    var hour = minute * 60;
    var day = hour * 24;
    var month = day * 30;

    var nowTime = (new Date()).getTime()/1000; // 获取当前时间戳
    var oldTime = nowTime - diffValue      // 获取记录到当前时间的距离
    
    var monthC =oldTime/month;
    var weekC =oldTime/(7*day);
    var dayC =oldTime/day;
    var hourC =oldTime/hour;
    var minC =oldTime/minute;
    var res = '';
    if(monthC>=12){
      var date = new Date(diffValue);
      res = date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();
  
    }else if(monthC>=1){
      res = parseInt(monthC) + "个月前";
    }
    else if(weekC>=1){
      res = parseInt(weekC) + "周前"
    }
    else if(dayC>=1){
      res = parseInt(dayC) +"天前"
    }
    else if(hourC>=1){
      res = parseInt(hourC) +"个小时前"
    }
    else if(minC>=1){
      res = parseInt(minC) +"分钟前"
    }else{
      res = "刚刚"
    }
    return res; 
  };
  
export function getToday() {
	var date = new Date(); 
	var year = date.getFullYear(); 
	var month = date.getMonth() + 1;
	var day = date.getDate();
	month = (month > 9) ? month : ("0" + month);
	day = (day < 10) ? ("0" + day) : day;
	var today = year + "-" + month + "-" + day;
	return today
};

export function randomString(len) {
　　len = len || 32;
　　var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';    /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
　　var maxPos = $chars.length;
　　var pwd = '';
　　for (var i = 0; i < len; i++) {
　　　　pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
　　}
　　return pwd;
}